package com.springcloud.tools.conf;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;

/**
 * @author fuc
 * @create 2020-06-08
 */
public class MyBatisPlusConfig {
  /** 分页插件 */
  @Bean
  public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    return paginationInterceptor;
  }

  /** 乐观锁插件 */
  public OptimisticLockerInterceptor optimisticLockerInterceptor() {
    return new OptimisticLockerInterceptor();
  }

  /** map结果集的下划线转驼峰 */
  @Bean
  public ConfigurationCustomizer mybatisConfigurationCustomizer() {
    return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
  }
}
